package com.yb.common.domain;

import java.util.HashMap;

import com.yb.common.constant.HttpStatusCode;

public class AjaxResult extends HashMap<String, Object> {
	
	private static final long serialVersionUID = 1L;
	
	/** 状态码 */
	public static final String CODE_TAG = "code";
	/** 返回内容 */
	public static final String MSG_TAG = "msg";
	/** 数据对象 */
	public static final String DATA_TAG = "data";
	
	public AjaxResult() {
	}
	public AjaxResult(int code, String msg) {
		super.put(CODE_TAG, code);
		super.put(MSG_TAG, msg);
	}
	public AjaxResult(int code, String msg, Object data) {
		super.put(CODE_TAG, code);
		super.put(MSG_TAG, msg);
		if (data != null) {
			super.put(DATA_TAG, data);
		}
	}
	
	public static AjaxResult success() {
		return new AjaxResult(HttpStatusCode.OK, "操作成功");
	}
	public static AjaxResult success(Object data) {
		return new AjaxResult(HttpStatusCode.OK, "操作成功", data);
	}
	public static AjaxResult success(int code, String msg) {
		return new AjaxResult(code, msg);
	}
	public static AjaxResult success(int code, String msg, Object data) {
		return new AjaxResult(code, msg, data);
	}
	
	public static AjaxResult error() {
		return new AjaxResult(HttpStatusCode.ERROR, "操作失败");
	}
	public static AjaxResult error(Object data) {
		return new AjaxResult(HttpStatusCode.ERROR, "操作失败", data);
	}
	public static AjaxResult error(int code, String msg) {
		return new AjaxResult(code, msg);
	}
	public static AjaxResult error(int code, String msg, Object data) {
		return new AjaxResult(code, msg, data);
	}
}
